package com.arlain.mq.rocket.retry;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.common.RemotingHelper;

import java.util.Date;

/**
 * Broadcasting is sending a message to all subscribers of a topic. If you want all subscribers receive messages about a topic, broadcasting is a good choice.
 */
public class BroadcastProducer {
    public static void main(String[] args) throws Exception {
        DefaultMQProducer producer = new DefaultMQProducer("clusteringProducer");
        producer.setNamesrvAddr("10.201.7.160:9876");
        producer.setInstanceName("clusteringProducer");
        producer.start();

        for (int i = 0; i < 10; i++) {
            Message msg = new Message("TopicBroadcast",
                    "TagA",
                    "OrderID188",
                    ("Hello world-" + i + " " + new Date()).getBytes(RemotingHelper.DEFAULT_CHARSET));
            SendResult sendResult = producer.send(msg);
            System.out.printf("%s%n", sendResult);
        }
        producer.shutdown();
    }
}